WPS Office.apk(点击下载) / clj.java


package defpackage;

import android.support.v4.media.session.PlaybackStateCompat;
import cn.wps.core.runtime.Platform;
import cn.wps.moffice.crash.FileDamagedException;
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

/* renamed from: clj  reason: default package */
public final class clj {
    private static final String TAG = clj.class.getSimpleName();
    private ZipFile ckh = null;
    public clm cki;
    private clg ckj = null;
    private String ckk = null;
    public String ckl = null;

    public clj(String str) throws IOException {
        try {
            this.ckh = new ZipFile(str);
            this.cki = new clm(this.ckh, "");
        } catch (IOException e) {
            this.ckk = File.createTempFile("FileRepair.", ".ooxml.tmp", new File(Platform.getTempDirectory())).getAbsolutePath();
            K(str, this.ckk);
            this.ckl = e.toString();
            this.ckh = new ZipFile(this.ckk);
            this.cki = new clm(this.ckh, "");
        } catch (ArrayIndexOutOfBoundsException e2) {
            throw new FileDamagedException(e2);
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:21:0x00a0, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:23:?, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:24:0x00a4, code lost:
        r5.flush();
        defpackage.lul.closeQuietly(r5);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:25:0x00ae, code lost:
        if (r7.exists() != false) goto L_0x00b0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:26:0x00b0, code lost:
        r7.delete();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:33:0x00c2, code lost:
        r4.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:36:0x00cb, code lost:
        r7.delete();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:53:0x0117, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:54:0x0118, code lost:
        r1 = true;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:64:?, code lost:
        return;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:65:?, code lost:
        return;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:21:0x00a0 A[ExcHandler: Exception (r0v5 'e' java.lang.Exception A[CUSTOM_DECLARE]), Splitter:B:1:0x002d] */
    /* JADX WARNING: Removed duplicated region for block: B:33:0x00c2  */
    /* JADX WARNING: Removed duplicated region for block: B:36:0x00cb  */
    private static void K(String str, String str2) throws IOException {
        Throwable th;
        boolean z = false;
        ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(str));
        ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(str2));
        byte[] bArr = new byte[4096];
        File createTempFile = File.createTempFile("FileRepair.", ".pptx.tmp", new File(Platform.getTempDirectory()));
        ZipEntry zipEntry = null;
        while (true) {
            try {
                ZipEntry nextEntry = zipInputStream.getNextEntry();
                if (nextEntry != null) {
                    FileOutputStream fileOutputStream = new FileOutputStream(createTempFile);
                    while (true) {
                        try {
                            int read = zipInputStream.read(bArr);
                            if (read <= 0) {
                                break;
                            }
                            fileOutputStream.write(bArr, 0, read);
                        } catch (Exception e) {
                            e.printStackTrace();
                            lul.a(fileOutputStream);
                            z = true;
                        } catch (Throwable th2) {
                            th = th2;
                            lul.a(fileOutputStream);
                            throw th;
                        }
                    }
                    lul.a(fileOutputStream);
                    if (nextEntry.getSize() <= 0 || nextEntry.getSize() <= createTempFile.length()) {
                        ZipEntry zipEntry2 = new ZipEntry(nextEntry.getName());
                        zipOutputStream.putNextEntry(zipEntry2);
                        FileInputStream fileInputStream = new FileInputStream(createTempFile);
                        while (true) {
                            int read2 = fileInputStream.read(bArr);
                            if (read2 > 0) {
                                zipOutputStream.write(bArr, 0, read2);
                            } else {
                                try {
                                    break;
                                } catch (ZipException e2) {
                                    hm.e(TAG, "closeEntry: failed");
                                    zipEntry = zipEntry2;
                                }
                            }
                        }
                        zipOutputStream.closeEntry();
                        zipInputStream.closeEntry();
                        fileInputStream.close();
                        zipEntry = zipEntry2;
                    } else {
                        throw new EOFException(nextEntry.getName() + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + Long.toString(nextEntry.getSize()) + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + Long.toString(zipEntry.getSize()));
                    }
                } else {
                    zipOutputStream.flush();
                    lul.closeQuietly(zipOutputStream);
                    if (!z) {
                        zipInputStream.close();
                    }
                    if (createTempFile.exists()) {
                        createTempFile.delete();
                        return;
                    }
                    return;
                }
            } catch (Exception e3) {
            } catch (Throwable th3) {
                Throwable th4 = th3;
                zipOutputStream.flush();
                lul.closeQuietly(zipOutputStream);
                if (!z) {
                }
                if (createTempFile.exists()) {
                }
                throw th4;
            }
        }
    }

    static InputStream a(ZipFile zipFile, String str) throws IOException {
        ZipEntry b = b(zipFile, str);
        if (b == null) {
            return null;
        }
        try {
            return zipFile.getInputStream(b);
        } catch (ZipException e) {
            return null;
        }
    }

    static InputStream a(ZipFile zipFile, ZipEntry zipEntry) throws IOException {
        try {
            return zipFile.getInputStream(zipEntry);
        } catch (Throwable th) {
            hm.e(TAG, "Throwable", th);
            return null;
        }
    }

    static ZipEntry b(ZipFile zipFile, String str) {
        if (str == null) {
            return null;
        }
        ZipEntry entry = zipFile.getEntry(str);
        return entry == null ? zipFile.getEntry(str.replace('/', '\\')) : entry;
    }

    public final cli apA() {
        Iterator<cll> it = this.cki.cks.iterator();
        while (it.hasNext()) {
            cll next = it.next();
            if (next.ckp.equals(cky.ciX.ciT)) {
                return (cli) next.apG();
            }
        }
        return null;
    }

    public final int apB() {
        int i = 0;
        Enumeration<? extends ZipEntry> entries = this.ckh.entries();
        while (entries.hasMoreElements()) {
            ZipEntry zipEntry = (ZipEntry) entries.nextElement();
            String name = zipEntry.getName();
            if (name.endsWith(".xml")) {
                i = (int) ((zipEntry.getSize() << 1) + ((long) i));
            } else if (name.contains("/media/image")) {
                long compressedSize = zipEntry.getCompressedSize();
                if (compressedSize < PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE) {
                    i = (int) (((long) i) + (compressedSize << 2));
                } else {
                    i = (int) (((long) i) + (compressedSize << 1));
                }
            } else {
                i = i;
            }
        }
        return i;
    }

    public final int apC() {
        int i = 0;
        Enumeration<? extends ZipEntry> entries = this.ckh.entries();
        while (entries.hasMoreElements()) {
            ZipEntry zipEntry = (ZipEntry) entries.nextElement();
            if (zipEntry.getName().contains("/media/")) {
                i = (int) (zipEntry.getCompressedSize() + ((long) i));
            } else {
                i = i;
            }
        }
        return i;
    }

    public final clk apx() {
        Iterator<cll> it = this.cki.cks.iterator();
        while (it.hasNext()) {
            cll next = it.next();
            if (next != null && next.ckp != null && next.ckp.equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument")) {
                return next.apG();
            }
        }
        return null;
    }

    public final clf apy() {
        Iterator<cll> it = this.cki.cks.iterator();
        while (it.hasNext()) {
            cll next = it.next();
            if (cky.ciV.ciT.equals(next.ckp)) {
                return (clf) next.apG();
            }
        }
        return null;
    }

    public final clh apz() {
        Iterator<cll> it = this.cki.cks.iterator();
        while (it.hasNext()) {
            cll next = it.next();
            if (next.ckp.equals(cky.ciW.ciT)) {
                return (clh) next.apG();
            }
        }
        return null;
    }

    public final void close() throws IOException {
        if (this.ckh != null) {
            this.ckh.close();
            this.ckh = null;
            if (this.ckk != null) {
                File file = new File(this.ckk);
                if (file.exists()) {
                    file.delete();
                }
            }
        }
    }

    public final String fU(String str) {
        if (this.ckj == null) {
            try {
                this.ckj = new clg(this.ckh);
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
        clg clg = this.ckj;
        if (!str.startsWith("/")) {
            str = "/" + str;
        }
        return clg.cjV.get(str);
    }

    public final String fV(String str) {
        if (this.ckj == null) {
            try {
                this.ckj = new clg(this.ckh);
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
        return this.ckj.cjU.get(str);
    }
}